To have the best of both worlds is to enjoy the advantages of two different situations at once. For example, a hybrid job provides the social connections of working in an office and the flexibility of working from home.
You have the best of both worlds when you're able to enjoy the advantages of two very different scenarios without the usual trade-offs. This idiom is often used to describe a situation where someone has found a perfect middle ground. For example, living in a quiet, rural town that is only a short train ride from a major city offers the peace of the countryside and the excitement of urban life. When you have the best of both worlds, you get the upsides of both situations.